var names = ["frank", "wyh", "kobe", "jemas"];

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
    this._address = "北京市";
  }

  // 普通的类方法
  eating() {
    console.log(this.name + " eating~");
  }
  running() {
    console.log(this.name + " running~");
  }

  // 类的访问器方法
  get address() {
    return this._address;
  }
  set address(value) {
    this._address = value;
  }

  // 类的静态方法(类方法)
  // Person.randomPerson()
  static randomPerson() {
    var nameIndex = Math.floor(Math.random() * names.length);
    var name = names[nameIndex];
    var age = Math.ceil(Math.random() * 100);
    return new Person(name, age);
  }
}

var p = new Person("frank", 18);
p.eating();
p.running();

console.log(p.address);
p.address = "上海市";
console.log(p.address);

// console.log(Object.getOwnPropertyDescriptors(p));
// console.log(Object.getOwnPropertyDescriptors(Person.prototype));
// console.log(Person.prototype.__proto__.__proto__);

for (var i = 0; i < 10; i++) {
  console.log(Person.randomPerson());
}
